package offer;

import java.util.ArrayList;

/**
 * @Author SSK
 * @Date Created in 17:53 2019/8/4
 * @Description 和为S的连续正数序列
 * @Version 1.0
 */
public class T42 {
    public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {
        ArrayList<ArrayList<Integer>>  lists= new ArrayList<ArrayList<Integer>>();
        for (int i = (int) Math.sqrt(sum*2); i >=2 ; i--) {
            double x =  2.00 * sum -i*i;
            x /=i;
            if ((x!=(int)x)||x<1||x%2==0) {
                continue;
            }
            int n =  ((int) x+1)/2;
            ArrayList<Integer> temp = new ArrayList<Integer>();
            for (int j = 0; j < i; j++) {
                temp.add(j+n);
            }
            lists.add(temp);
        }
        return lists;
    }
    public static void main ( String[] args) {
        System.out.println(new T42().FindContinuousSequence(3));

    }
}
